#!/usr/bin/env python
import sys
from lib.format_time import *
from lib.HandleMysql import *
from lib.switch_code import *
from shop_conn import *
import sys
import re
import os
sys.setdefaultencoding('utf-8')

def execute(  ):    
    query = ""
    conn = set_product_conn()
    stat_conn = set_stats_conn()
    stat_table = "shop_info"
    #
    query = "select ifnull(max(prod_id),0) from t_product"
    items = stat_conn.get_results(query)
    maxid = items[0][0]
    
    print maxid
    query = "select productid,salestate from t_product where productid>%s "%maxid
    items = conn.get_results(query)
    for item in items:
        prod_id = item[0]
        sale_state = item[1]
        sql = "insert into t_product(prod_id,sale_state) values(%s,%s)"%(prod_id,sale_state)
        stat_conn.execute_sql(sql)

if __name__=='__main__':
    execute( )